package cn.com.w.commons.base;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;

public class test {

    static class Person {

        String name;
        int age;
        String address;

        public Person(String name, int age, String address) {
            this.name = name;
            this.age = age;
            this.address = address;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }



        @Override
        public String toString() {
            return "Person{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    ", address='" + address + '\'' +
                    '}';
        }
    }


    public static void main(String[] args) {
        List<Person> list = new ArrayList<>();
        list.add(new Person("Tom", 15, "America"));
        list.add(new Person("Tom", 15, "America"));
        list.add(new Person("Tom", 20, "America"));

        list.add(new Person("Tam", 16, "China"));
        list.add(new Person("Tam", 16, "China"));

        list.add(new Person("Tom", 15, "Japan"));

        list.add(new Person("Tcm", 18, "Russia"));

        list.add(new Person("Tdm", 16, "America"));

        list.add(new Person("Tem", 17, "America"));

        // 根据三个字段去重
        List<Person> lst = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(
                () -> new TreeSet<>(Comparator.comparing(o -> o.getName() + "#" + o.getAge() ))),
                ArrayList::new));

        // 遍历输出一下
        lst.forEach(person -> System.out.println(person.toString()));

    }


}
